<?php

namespace app\api\controller;

use app\common\lib\Param;
use app\common\lib\Show;
use app\common\lib\Str;
use app\Request;
use think\facade\Cache;
use think\response\Json;

class Video extends ApiBase
{

    public function index(){
        $limit = input("limit", 0, "intval");
        //$category_id = input("category_id", 0, "intval");

        $videoBis = new \app\common\business\Video();
        $map = [];
        //$category_id != 0 && $map[] = ['category_id','=',$category_id];

        try {
            $list = $videoBis->getListByWhereWithLimit($map,$limit,'sort desc,id asc');
        } catch (\Exception $e) {
            return Show::error([], $e->getMessage(), $e->getCode());
        }

        return Show::success($list);
    }

    public function detail(): Json
    {
        $id = input("id", 0, "intval");

        $videoBis = new \app\common\business\Video();

        try {
            $info = $videoBis->getNormalById($id);
        } catch (\Exception $e) {
            return Show::error([], $e->getMessage(), $e->getCode());
        }

        !empty($info) && $info = $videoBis->resetInfo([$info]);
        return Show::success($info);
    }
}